<?php
defined('IN_YuLin') || exit('NO PERMIT!');
$table = Table('activity');
switch ($a) {
	case 'send':		
		$o = intval($_GET['o']);
		if(!$o){
			$tpl->display($m.'/'.$a . '_add');return;
		}
		if(IS_POST){
			$id = intval($_POST['id']);
			$thumb = UploadFile("file");
			if($thumb['error'] == 0){
				$data['thumb'] = $thumb['url'];
			}
			$data['title'] =  NoBadStr($_POST['title']);
			$data['desc'] =  NoBadStr($_POST['desc']);
			$data['source'] = intval($_POST['source']);
			$data['isPic'] = intval($_POST['isPic']);
			$contents = $data['isPic'] == 0 ? NoBadStr($_POST['contents']) : UploadFile("fileContent")['url'];
			!empty($contents) && $data['contents'] = $contents;
			$data['inputtime'] = time();
			if($id){
		        $res = $db->exec('UPDATE '.$table." SET ".CreateUpdateSql($data)." where id = $id");
			}else{
		        $res = $db->exec('INSERT INTO '.$table.CreateInsertSql($data));
			}
	        ShowMsg('操作成功',U($m.'/manage'));
		}else{
			$data = $db->getrow("SELECT * from ".$table." where id = $o");
			$tpl->display($m.'/'.$a);
		}
		break;

	case 'edit':
		$data['status'] = intval($_GET['_s']) ? 0 : 1;
		$id = intval($_GET['o']);
		$res = $db->exec("UPDATE ".$table." SET ".CreateUpdateSql($data)." where id = $id");
		ShowMsg('操作成功',U($m.'/'.$c));
		break;

	case 'delete':
		$ids = NoBadStr($_POST['ids']);
		$res = $db->exec("delete from ".$table." where id in (".$ids.")");
		echo $res;
		break;
	
	default:
		$table = Table('activity');
		$data = $db->getall('SELECT * from '.$table." order by id asc");
		$tpl->display($m.'/'.$c);
		break;
}